package main

import (
	"gorm.io/gen"
	"gorm.io/gen/field"
	"likeadmin/core"
)

func main() {
	g := gen.NewGenerator(gen.Config{
		OutPath:      "./dao",
		Mode:         gen.WithoutContext | gen.WithDefaultQuery | gen.WithQueryInterface, // generate mode
		ModelPkgPath: "./model",                                                          // 定义 model 文件输出目录
	})

	// gormdb, _ := gorm.Open(mysql.Open("root:@(127.0.0.1:3306)/demo?charset=utf8mb4&parseTime=True&loc=Local"))
	g.UseDB(core.GetDB()) // reuse your gorm db

	User := g.GenerateModel("user")
	// 退款日志
	Admin := g.GenerateModel("system_auth_admin")
	g.ApplyBasic(
		User,
		Admin,
		g.GenerateModel("user_account_log", gen.FieldRelate(field.BelongsTo, "User", User,
			&field.RelateConfig{
				// RelateSlice: true,
				GORMTag: field.GormTag{"foreignKey": []string{"UserID"}, "references": []string{"ID"}},
			})),

		g.GenerateModel("notice_setting"),

		g.GenerateModel("refund_log", gen.FieldRelate(field.BelongsTo, "Admin", Admin,
			&field.RelateConfig{
				// RelateSlice: true,
				GORMTag: field.GormTag{"foreignKey": []string{"HandleID"}, "references": []string{"ID"}},
			})),
		// 退款记录
		g.GenerateModel("refund_record", gen.FieldRelate(field.BelongsTo, "User", User,
			&field.RelateConfig{
				// RelateSlice: true,
				GORMTag: field.GormTag{"foreignKey": []string{"UserID"}, "references": []string{"ID"}},
			})),

		g.GenerateModel("recharge_order", gen.FieldRelate(field.BelongsTo, "User", User,
			&field.RelateConfig{
				// RelateSlice: true,
				GORMTag: field.GormTag{"foreignKey": []string{"UserID"}, "references": []string{"ID"}},
			})),
	)

	g.Execute()
}
